import time


from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait

d=webdriver.Edge()
#访问网址
d.get("http://127.0.0.1/ranzhi/www")
time.sleep(3)
#用户名和密码输入并登陆
locator = ("id","account")
input = WebDriverWait(d,5,0.5).until(expected_conditions.presence_of_element_located(locator))
d.find_element(By.ID,'account').send_keys('admin')
d.find_element(By.ID,'password').send_keys('123456')
locator1 = ("id","submit")
input1 = WebDriverWait(d,5,0.5).until(expected_conditions.presence_of_element_located(locator1))
d.find_element('id','submit').click()

#后台管理
locator2 = ("id","s-menu-superadmin")
input2 = WebDriverWait(d,5,0.5).until(expected_conditions.presence_of_element_located(locator2))
d.find_element('id','s-menu-superadmin').click()

#添加成员
locator7 = ("id","iframe-superadmin")
input7 = WebDriverWait(d,5,0.5).until(expected_conditions.presence_of_element_located(locator7))
iframe=d.find_element('id','iframe-superadmin')
d.switch_to.frame(iframe)
locator3 = ("link text","添加成员")
input3 = WebDriverWait(d,5,0.5).until(expected_conditions.presence_of_element_located(locator3))
d.find_element('link text',"添加成员").click()
#成员信息
#用户名
locator4 = ("id","account")
input4 = WebDriverWait(d,5,0.5).until(expected_conditions.presence_of_element_located(locator4))
d.find_element('id','account').send_keys('1234567890')
#真实姓名
d.find_element('id','realname').send_keys('God')
#性别
d.find_element('id','genderm').click()
#部门
dept=d.find_element('id','dept')
s=Select(dept)
ls1 = s.options
list1 = []
for i in ls1:
    list1.append(i.text)
s.select_by_value("11")
#角色
role=d.find_element('id','role')
r=Select(role)
ls2 = r.options
list2 = []
for m in ls2:
    list2.append(m.text)
r.select_by_value("top")
time.sleep(3)
#密码
d.find_element('id','password1').send_keys("1234567890")
#请重复密码
d.find_element('id','password2').send_keys("1234567890")
#邮箱
d.find_element('id','email').send_keys("1234567890@gmail.com")
#保存
d.find_element('id','submit').click()
#截图
locator5 = ("class name","table.table-hover.table-striped.table-bordered.tablesorter.table-fixed")
input5 = WebDriverWait(d,5,0.5).until(expected_conditions.presence_of_element_located(locator5))
timestr = time.strftime("%Y-%m-%d_%H-%M-%S",time.localtime())
d.get_screenshot_as_file(f"d:\\{timestr}.png")
time.sleep(3)





